import { List } from 'immutable';
import { isForm } from '@design/constant/component-type';

const Queries = {
  getAllFormNodes(editor) {
    const { document } = editor.value;
    function getFormNodes(node) {
      let list = List();
      if (isForm(node.type)) {
        list = list.push(node);
      }
      if (List.isList(node.nodes)) {
        list = list.concat(node.nodes.flatMap(getFormNodes));
      }
      return list;
    }
    return getFormNodes(document);
  }
};

export default Queries;
